const http = require('../../util/http')
Page({
  onShareAppMessage() {
    return {
      title: 'swiper',
      path: 'page/component/pages/swiper/swiper',
    };
  },
  data: {
    baseurl: http.baseURL,
    productName:"",
    fileUrl:"",
    mode: 'widthFix',
    scrollTop: 0,
    goodsList:['','','','',''],
    scrollIntoView: 'one',
    scrollLeft: 0,
    goodsList:[]
  },
  onLoad(option){
    console.log(option)
    this.setData({
      productName:option.productName,
      fileUrl:option.fileUrl,
    })
    this.getActivityInfo(option.activityId)
  },
  getActivityInfo(activityId){
    let parms = {
      activityId:activityId
    }
    xhs.showLoading({
      title: '加载中',
    })
    http.get('/api/activity/getActivityInfo',parms).then(res => {
      console.log('res',res)
      xhs.hideLoading()
			if (res.code == 200) {
        this.setData({
          goodsList:res.data.list
        })
			}
		})
  },
  openDetial(e) {
    console.log(e)
    const item = e.currentTarget.dataset.item
    xhs.navigateTo({
      url: '/entry/productDetail/index?id='+item.id
    });
  },
  creareOrder(e){
    console.log(e)
    const item = e.currentTarget.dataset.item
    let parms ={
      productId:item.id
    }
    http.get('/api/xhs/xhsBuyProduct',parms).then(res => {
      console.log('res',res)
			if (res.code == 200) {
        xhs.requestGuaranteeOrderPayment({
          orderInfo: {
            payToken: res.data.pay_token,
            orderId: res.data.order_id,
          },
          success: res => {
            xhs.hideLoading()
            xhs.showToast({
              title: '支付成功'
            })
            console.log('支付结果', res);
          },
          fail: res => {
            xhs.showToast({
              title: '支付失败',
              icon: 'none'
            });
            console.log('支付结果', res);
          },
        });
      } else if(res.code == 902){
        xhs.navigateTo({
          url: "/entry/login/index"
        });
      }
		})

  },
  scroll(e) {
    console.log('获取滚动事件的详细信息e.detail：', e.detail);
    // 此处只做对scrollTop值的监听，不需要使用setData对视图层发起更新
    this.data.scrollTop = e.detail.scrollTop;
  },
  upper() {
    xhs.showToast({
      title: '到顶了',
      icon: 'none'
    });
  },

  lower() {
    xhs.showToast({
      title: '到底了',
      icon: 'none'
    });
  },
  onChange(e) {
    console.log('swiper bindChange', e);
  },
});
